package com.firmboy.db;

import com.firmboy.threadPool.PoolFactory;
import com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList;
import org.junit.Test;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 测试连接池
 *
 * @author firmboy
 * @create 2018-04-15 下午7:27
 **/
public class DBTest {


    @Test
    public void dbTest(){

        final DBPoolHelper helper = new DBPoolHelper();

        Runnable my = new Runnable() {
            @Override
            public void run() {
                List<Map<String, Object>> list = helper.getListObject("select * from test_pool", new Object[]{});
            }
        };


        ThreadPoolExecutor pool = PoolFactory.getPool();

        pool.execute(my);
        pool.execute(my);
        pool.execute(my);
        pool.execute(my);
        pool.execute(my);
        pool.execute(my);
        pool.execute(my);
        pool.execute(my);
        pool.execute(my);
        pool.execute(my);


        while(true){}


    }

    @Test
    public void queueTest() throws InterruptedException {
        ArrayBlockingQueue queue = new ArrayBlockingQueue(3);

        queue.put(new Object());
        queue.put(new Object());
        queue.put(new Object());

        for (int i =0 ;i<5;i++){
            Object poll = queue.poll();
            if(poll!=null){
                System.out.println("队列中有数据");
            }else{
                System.out.println("队列中已无数据");
            }


        }


    }
}
